package org.nowcoder.huawei.c100;

/**
 * 35:最多购买宝石数目
 */
public class HC035 {
    public static void main(String[] args) {
        int n = 9;
        int[] gems = new int[]{6,1,3,1,8,9,3,2,4};
        int v = 15;
        solve(gems,n,v);
    }

    public static void solve(int[] gems, int n, int v) {
        int l = 0, r = 0;
        int max = Integer.MIN_VALUE, sum = 0;
        while (r < n) {
            sum += gems[r];
            //如果当前价值大于等于v
            if (sum > v) {
                sum -= gems[l++];
            } else {
                max = Math.max(max, r - l + 1);
            }
            r++;
        }
        System.out.println(max);
    }
}
